<?php
/*
 *author:Yangligao
 *Date:2013-10-8
 */
require 'Config.php';
require 'Public/Include/footer.php';
require 'Public/Include/adv.php';
$smarty->assign('positionFlag','搜索结果列表');

$serTypeId = $_GET['serTypeId'];
$search = $_GET['search'];
if($serTypeId == 'foodmenu'){//在菜单中查找
	$menuModel = new MenuModel();
	$searTotal = $menuModel->menu_select("count(*) as num","where menu_name like '%{$search}%'");
	$totalCount = $searTotal[0]['num'];
	$pageSize = 6;
	$pageModel = new Page($pageSize, $totalCount);
	
	$start = $pageModel->getStart();
	
	$searchRes = $menuModel->menu_select("menu_id,menu_name,menu_pic,menu_content","where menu_name like '%{$search}%'","limit {$start},{$pageSize}");

	$pageStr = $pageModel->getPageStr();
	for ($i=0;$i<count($searchRes);$i++){
		//替换  描红
		$searchRes[$i]['menu_name'] = str_replace($search, "<font style='color:red;'>".$search."</font>", $searchRes[$i]['menu_name']);
		
			if(strlen($searchRes[$i]['menu_content']) > 80){
				$searchRes[$i]['menu_content'] = mb_substr($searchRes[$i]['menu_content'], 0,270,'utf-8')."......";
			}
		}
	$smarty->assign('flag','menu');	

}else{//在食品中查找
	$foodModel = new FoodModel();
	$searchTotal = $foodModel->food_select("count(*) as num","where food_type={$serTypeId} and food_name like '%{$search}%'");
	$totalCount = $searchTotal[0]['num'];
	$pageSize = 6;
	$pageModel = new Page($pageSize, $totalCount);
	$start = $pageModel->getStart();
	$searchRes = $foodModel->food_select("food_id,food_name,food_pic,food_content","where food_type='{$serTypeId}' and food_name like '%{$search}%'","limit {$start},{$pageSize}");
	$pageStr = $pageModel->getPageStr();
	for ($i=0;$i<count($searchRes);$i++){
		//替换  描红
		$searchRes[$i]['food_name'] = str_replace($search, "<font style='color:red;'>".$search."</font>", $searchRes[$i]['food_name']);
	
		if(strlen($searchRes[$i]['food_content']) > 80){
			$searchRes[$i]['food_content'] = mb_substr($searchRes[$i]['food_content'], 0,270,'utf-8')."......";
		}
	}
	$smarty->assign('flag','food');
}
$smarty->assign('pageStr',$pageStr);
$smarty->assign('searchRes',$searchRes);
$smarty->display('Index/headsearch.html');
?>
